using System.Drawing;
using System.Windows.Forms;

namespace lab04
{
    interface IMatrixDrawer
    {
        void DrawBorder(int M, int N);
        void DrawCell(int i, int j);
        void DrawValue(int i, int j, int value);
    }

    class MatrixDrawer : IMatrixDrawer
    {
        public MatrixDrawer()
        {
            CellWidth = 25;
            CellHeight = 25;
        }

        public Color CellBorderColor { get; set; }
        public Color CellEmptyBackgroundColor { get; set; }
        public Color CellFullBackgroundColor { get; set; }
        public int CellHeight { get; set; }
        public int CellWidth { get; set; }
        public Color MatrixBackgroundColor { get; set; }
        public Color MatrixBorderColor { get; set; }
        public Panel Panel { get; set; }
        public bool ShadowsEnable { get; set; }


        public void DrawBorder(int M, int N)
        {
            using (Graphics g = Graphics.FromHwnd(Panel.Handle))
            {
                using (SolidBrush brush = new SolidBrush(MatrixBackgroundColor))
                {
                    using (Pen pen = new Pen(MatrixBorderColor, 1))
                    {
                        g.DrawRectangle(pen, 0, 0, N*(10 + CellWidth) + 10, M*(10 + CellHeight) + 10);
                    }
                    g.FillRectangle(brush, 1, 1, N*(10 + CellWidth) + 9, M*(10 + CellHeight) + 9);
                }
            }
        }

        public void DrawCell(int i, int j)
        {
            using (Graphics g = Graphics.FromHwnd(Panel.Handle))
            {
                using (Pen pen = new Pen(CellBorderColor, 1))
                {
                    using (SolidBrush brush = new SolidBrush(CellEmptyBackgroundColor))
                    {
                        g.DrawRectangle(pen, 11 + j*(10 + CellWidth), 11 + i*(10 + CellHeight), CellWidth,
                                        CellHeight);
                        if (ShadowsEnable)
                            g.DrawRectangle(pen, 12 + j*(10 + CellWidth), 12 + i*(10 + CellHeight), CellWidth,
                                            CellHeight);
                        g.FillRectangle(brush, 12 + j*(10 + CellWidth), 12 + i*(10 + CellHeight), CellWidth - 1,
                                        CellHeight - 1);
                    }
                }
            }
        }

        public void DrawValue(int i, int j, int value)
        {
            using (Graphics g = Graphics.FromHwnd(Panel.Handle))
            {
                using (SolidBrush brush = new SolidBrush(CellFullBackgroundColor))
                {
                    g.FillRectangle(brush, 12 + j*(10 + CellWidth), 12 + i*(10 + CellHeight), CellWidth - 1,
                                    CellHeight - 1);
                }
                using (SolidBrush textBrush = new SolidBrush(Color.Black))
                {
                    g.DrawString(value.ToString(), new Font("Consolas", CellHeight/2 - 2, FontStyle.Regular), textBrush,
                                 15 + j*(10 + CellWidth), 14 + i*(10 + CellHeight));
                }
            }
        }

    }

    internal class ColorWithoutShadows : MatrixDrawer
    {
        public ColorWithoutShadows()
        {
            MatrixBorderColor = Color.Black;
            MatrixBackgroundColor = Color.LightCyan;
            CellBorderColor = Color.Black;
            CellEmptyBackgroundColor = Color.LightSkyBlue;
            CellFullBackgroundColor = Color.LightPink;
            ShadowsEnable = false;
        }
    }

    internal class ColorWithShadows : MatrixDrawer
    {
        public ColorWithShadows()
        {
            MatrixBorderColor = Color.Black;
            MatrixBackgroundColor = Color.LightCyan;
            CellBorderColor = Color.Black;
            CellEmptyBackgroundColor = Color.LightSkyBlue;
            CellFullBackgroundColor = Color.LightPink;
            ShadowsEnable = true;
        }
    }

    internal class BwWithoutShadows : MatrixDrawer
    {
        public BwWithoutShadows()
        {
            MatrixBorderColor = Color.Black;
            MatrixBackgroundColor = Color.FromArgb(240, 240, 240);
            CellBorderColor = Color.Black;
            CellEmptyBackgroundColor = Color.FromArgb(160, 160, 160);
            CellFullBackgroundColor = Color.LightGray;
            ShadowsEnable = false;
        }
    }

    internal class BwWithShadows : MatrixDrawer
    {
        public BwWithShadows()
        {
            MatrixBorderColor = Color.Black;
            MatrixBackgroundColor = Color.FromArgb(240, 240, 240);
            CellBorderColor = Color.Black;
            CellEmptyBackgroundColor = Color.FromArgb(160, 160, 160);
            CellFullBackgroundColor = Color.LightGray;
            ShadowsEnable = true;
        }
    }
}